package com.hsck.order.kds.setup.adapter

import androidx.annotation.LayoutRes
import com.hsck.order.kds.R
import com.hsck.order.kds.base.bean.SetupBean
import com.hsck.order.kds.base.common.BaseAdapter
import com.hsck.order.kds.base.common.BaseViewHolder
import com.hsck.order.kds.base.common.setOnSingleClickListener
import com.hsck.order.kds.base.common.setSpannableString
import com.hsck.order.kds.base.utils.LogUtil
import kotlinx.android.synthetic.main.item_setup.view.*

/**
 * 设置左侧分类-适配器
 */
class SetupAdapter(@LayoutRes layoutId: Int) : BaseAdapter<SetupBean>(layoutId) {

    var onPositionClick: ((SetupBean, Int) -> Unit) = { showBean, index -> }

    override fun onBindViewHolder(holder: BaseViewHolder, data: SetupBean) {
        holder.itemView.tv_item_setup.text = "${data.name}"
        holder.itemView.img_item_setup.setImageResource(data.code)
        holder.itemView.img_item_setup.isSelected = data.isSelected
        if (data.isSelected) {
            holder.itemView.setBackgroundResource(R.drawable.shape_gray3e_borderless20)
            holder.itemView.tv_item_setup.setSpannableString(colorId = R.color.white)
        } else {
            holder.itemView.setBackgroundResource(R.color.gray29)
            holder.itemView.tv_item_setup.setSpannableString(colorId = R.color.grayAE)

        }
        holder.itemView.setOnSingleClickListener {
            try {
                onPositionClick.invoke(data, holder.adapterPosition)
            } catch (e: Exception) {
                LogUtil.e("error" + e.message)
            }
        }
    }
}